package com.atguigu.base;

import javax.servlet.http.HttpServletRequest;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;

/**
 * projectName: shf
 *
 * @author: cbc
 * time: 2022/6/7 14:26 周二
 * description:
 */

public class BaseController {
    //不能使用私有的，否则子类不能使用
    protected Map<String, Object> getFilters(HttpServletRequest request) {
        //获取表单中所有具有name属性的表单对象，返回值为Enumeration
        Enumeration parameterNames = request.getParameterNames();
        Map<String, Object> filters = new HashMap<>();
        //效验前端传递过来的参数是否有值
        while (parameterNames != null && parameterNames.hasMoreElements()) {
            String parameName = (String) parameterNames.nextElement();
            //获取值
            String[] Values = request.getParameterValues(parameName);
            filters.put(parameName, Values[0]);
        }
        //如果没有pageNum参数，则给pageNum为1
        if (!filters.containsKey("pageNum")) {
            filters.put("pageNum", 1);
        }
        //如果没有pageSize参数，则给pageSize为1
        if (!filters.containsKey("pageSize")) {
            filters.put("pageSize", 3);
        }
        return filters;
    }
}
